<template>
  <van-form @submit="onSubmit">
    <van-cell-group inset>
      <van-field
        v-model="userLogonData.userAccount"
        name="账号"
        label="账号"
        placeholder="账号"
        :rules="[{ required: true, message: '请填写账号' }]"
      />
      <van-field
        v-model="userLogonData.planetCode"
        name="星球编号"
        label="星球编号"
        placeholder="星球编号"
        :rules="[{ required: true, message: '请填写星球编号' }]"
      />
      <van-field
        v-model="userLogonData.userPassword"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <van-field
        v-model="userLogonData.checkPassword"
        type="password"
        name="确认密码"
        label="确认密码"
        placeholder="确认密码"
        :rules="[{ required: true, message: '请密码' }]"
      />
    </van-cell-group>
    <div style="margin: 16px">
      <van-button round block type="primary" native-type="submit">
        提交
      </van-button>
    </div>
  </van-form>
</template>

<script setup>
import { ref } from "vue";
import { useRouter } from "vue-router";
import axiosUrl from "../plugins/myAxios";
import { showToast } from "vant";

const router = useRouter();

const infoLogonDta = {
  userAccount: "",
  planetCode: "",
  userPassword: "",
  checkPassword: "",
};
const userLogonData = ref({ ...infoLogonDta });

const onSubmit = async () => {
  const postData = {
    ...userLogonData.value,
  };
  const res = await axiosUrl.post("/user/register", postData);
  if(res.data) {
    showToast("注册成功");
  } else {
    showToast("注册失败",res?.description);
  }
};
</script>

<style>
</style>